package com.qtenv.datasync.service.controller;


import com.qtenv.datasync.base.Result;
import com.qtenv.datasync.service.service.TerminalsService;
import com.qtenv.datasync.utils.CustomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 大表档案表 前端控制器
 * </p>
 *
 * @author CBL
 * @since 2022-08-02
 */
@RestController
@RequestMapping("/terminals")
public class TerminalsController {
    @Autowired
    private TerminalsService terminalsService;

    @GetMapping("/getTerminals")
    public Result<?> getTerminals(@RequestParam("tenantId") String tenantId) {
        System.out.println("zone getTerminals");
        return Result.ok(terminalsService.getTerminals(tenantId));
    }

    @GetMapping("/getTerminalBasicInfo")
    public Result<?> getTerminalBasicInfo(@RequestParam("tenantId") String tenantId, @RequestParam("terminalId") String terminalId) {
        String[] keyArr = {"设备ID", "设备名称", "口径（DN）", "安装地址", "采集频率（分）"};
        String[] valueArr = {"TerminalID", "TerminalName", "Caliber", "TerminalInstallAddr", "CollectionFrequency"};
        return Result.ok(CustomUtil.transformZbxToTextValueList(terminalsService.getTerminalBasicInfo(tenantId, terminalId), keyArr, valueArr));
    }

    @GetMapping("/getAllTerminalDataList")
    public Result<?> getAllTerminalDataList(@RequestParam("tenantId") String tenantId, @RequestParam(value = "terminalName", required = false) String terminalName,
                                            @RequestParam(value = "terminalInstallAddr", required = false) String terminalInstallAddr,
                                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") String pageSize,
                                            @RequestParam(value = "page", required = false, defaultValue = "1") String page) {
        System.out.println("zone getTerminals");
        return Result.ok(terminalsService.getAllTerminalDataList(tenantId, terminalName, terminalInstallAddr, page, pageSize));
    }
}
